package web.simulation.memento;


public class Operation implements OperationApi{

	private int result; 

	@Override
	public Memento createMemento() { 
		return new MementoImpl(this.result);
	}
 
	@Override
	public int add(int num) { 
		return result + num;
	} 
	@Override
	public int sub(int num) { 
		return result - num;
	}
	
	private static class MementoImpl implements Memento{
		
		private int result;
		
		public MementoImpl(int result){
			this.result = result;
		}
		
		public int getResult(){
			return this.result;
		}
	}

	@Override
	public void setMemento(Memento memento) {
		MementoImpl m = (MementoImpl)memento;
		this.result = m.getResult();
	}

	@Override
	public int getResult() { 
		return this.result;
	}
}
